package com.hmkj.admin.controller.order;

import com.hmkj.admin.controller.BaseController;
import com.hmkj.admin.utils.AdminSessionHelper;
import com.hmkj.core.po.order.Order;
import com.hmkj.core.po.system.Admin;
import com.hmkj.core.service.order.OrderService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(BaseController.BASE_URI)
public class OrderController extends BaseController{

    @Resource
    private OrderService orderService;

    /**
     * 订单列表 匹配中
     */
    @RequestMapping("/order/list")
    public String list(HttpServletRequest request) throws Exception {
        Admin admin = AdminSessionHelper.getCurrAdmin();
        request.setAttribute("admin", admin);
        return ok("order/order/list");
    }
    /**
     * 持仓列表
     */
    @RequestMapping("myOrder/hold/list")
    public  String holdList(HttpServletRequest request) throws Exception{
        Admin admin=AdminSessionHelper.getCurrAdmin();
        request.setAttribute("admin",admin);
        return  ok("myOrderHold/myOrderHold/list");
    }

    /**
     * 平仓中列表
     */
    @RequestMapping("myOrder/pingcanging/list")
    public String pingcangingList(HttpServletRequest request) throws Exception {
        Admin admin = AdminSessionHelper.getCurrAdmin();
        request.setAttribute("admin", admin);
        return ok("myOrderPingcanging/myOrderPingcanging/list");
    }
    /**
     * 待结算列表
     */
    @RequestMapping("myOrder/waitAccount/list")
    public String waitAccountedlist(HttpServletRequest request) throws Exception {
        Admin admin = AdminSessionHelper.getCurrAdmin();
        request.setAttribute("admin", admin);
        return ok("myOrderWaitAccount/list");
    }
    /**
     * 已结算列表
     */
    @RequestMapping("myOrder/accounted/list")
    public String accountedList(HttpServletRequest request) throws Exception {
        Admin admin = AdminSessionHelper.getCurrAdmin();
        request.setAttribute("admin", admin);
        return ok("myOrderAccounted/list");
    }
    /**
     * 流单列表
     */
    @RequestMapping("myOrder/liudan/list")
    public String lidanList(HttpServletRequest request) throws Exception {
        Admin admin = AdminSessionHelper.getCurrAdmin();
        request.setAttribute("admin", admin);
        return ok("myOrderLiudan/myOrderLiudan/list");
    }
    /**
     * 我的订单列表
     */
    @RequestMapping("/myOrder/list")
    public String myList(HttpServletRequest request) throws Exception {
        Admin admin = AdminSessionHelper.getCurrAdmin();
        request.setAttribute("admin", admin);
        return ok("myOrder/myOrder/list");
    }
    /**
     * 所有订单列表
     */
    @RequestMapping("/waitBalance/list")
    public String waitBalanceList() {
        return getAdminTemplate("waitBalance/waitBalance/list");
    }

    /**
     * 所有订单-查看订单详情
     */
    @RequestMapping(value = "/waitBalance/look", method = RequestMethod.GET)
    public String lookOrder(Order order, ModelMap modelMap) throws Exception {
        Order ord = orderService.selectByPrimaryKey(order.getId());
        modelMap.addAttribute("order", ord);
        return ok("waitBalance/waitBalance/look");
    }
    /**
     * 订单详情
     */
    @RequestMapping("orderHold/look")
    public String lookUser(Integer id, ModelMap modelMap) throws Exception {
        Order ord = orderService.selectByPrimaryKey(id);
        if (ord != null) {
            modelMap.addAttribute("order", ord);
        }
        //根据订单查询投资人id，根据投资人id和订单id查询对应资金记录
        modelMap.addAttribute("investId", ord.getInvestorId());
        return ok("/myOrderHold/myOrderHold/look");
    }

    /**
     * 资金明细
     */
    @RequestMapping("/order/moneyDetail")
    public String moneyDetail(Order order, ModelMap modelMap) throws Exception {
        Order ord = orderService.selectByPrimaryKey(order.getId());
        if (ord != null) {
            modelMap.addAttribute("order", ord);
            //根据订单查询投资人id，根据投资人id和订单id查询对应资金记录
            modelMap.addAttribute("investId", ord.getInvestorId());
        }
        return ok("/myOrderHold/myOrderHold/moneyDetail");
    }

    /**
     * 订单操作日志
     */
    @RequestMapping("/order/orderOperation")
    public String orderOperation(Order order, ModelMap modelMap) throws Exception {
        Order ord = orderService.selectByPrimaryKey(order.getId());
        if (ord != null) {
            modelMap.addAttribute("order", ord);
            //根据订单查询投资人id，根据投资人id和订单id查询对应资金记录
            modelMap.addAttribute("investId", ord.getInvestorId());
        }
        return ok("/myOrderHold/myOrderHold/orderOperation");
    }

}
